package king.dao.impl;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import king.Utils.JDBCUtils;
import king.dao.UserDao;
import king.domain.Student;
import king.domain.User;

public class UserDaoImpl implements UserDao {

	private Connection connection=JDBCUtils.getConnection();
	private PreparedStatement prepareStatement=null;
	
	public List<User> findAll() {
		String sql="select * from user";
		List<User> users = new ArrayList<User>();
		try {
			prepareStatement = connection.prepareStatement(sql);
			ResultSet resultSet=prepareStatement.executeQuery(sql);
			User user=null;
			while(resultSet.next()) {
				user=new User();
				user.setPassword(resultSet.getString("password"));
				user.setUsername(resultSet.getString("username"));
				users.add(user);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return users;
	}
	
	
}
